package com.ld.kafka;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import java.util.Date;

//@Component
public class KafkaSender {

//    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    public void send(){
        Message message = new Message();
        message.setId(System.currentTimeMillis());
        message.setMsg("测试消息，asdad,");
        message.setSendTime(new Date());
        System.out.println("Kafka 发送的消息："+ JSON.toJSONString(message));
        kafkaTemplate.send("test",JSON.toJSONString(message));
    }
}
